program fopen
implicit none
integer :: stat
integer :: i
open(unit=15,action="READWRITE", file="RESTART", status="OLD", &
  form="unformatted", IOSTAT=stat)
if(stat>0) then
  close(15)
  print *, "file does not exist"
  open(unit=15,action="WRITE", form="unformatted",file="RESTART", status="NEW", IOSTAT=stat)
  write(15) 123
else
  read(15) i
  write(*,*) "i = ", i
  write(15) 456
end if

close(15)


end program
